class Solution {
public:
    double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
        int m = 0, n = 0;
        int pre_v, v = 0;
        int v1, v2;
        int i;
        for(i = 0; i <= (nums1.size() + nums2.size()) / 2; ++i ) {
            v1 = (m < nums1.size()) ? nums1.at(m) : 100002;
            v2 = (n < nums2.size()) ? nums2.at(n) : 100002;
            pre_v = v;
            if (v1 < v2) {
                v = v1;
                m++;
            } else {
                v = v2;
                n++;
            }
        }
        double ans;
        if((nums1.size() + nums2.size()) % 2 == 0) {
            ans = (pre_v + v) / 2.0;
        } else {
            ans = v;
        }
        return ans;
    }
};